<template>
	<view v-if="info">
		<u-navbar title="订单详情" :border-bottom="false"></u-navbar>
		<view class="top">
			<view class="title">
				{{info.status_text}}
			</view>
			
		</view>
		
		<view class="address">
			<view class="left">
				<image src="../../static/image/a1_.png" mode=""></image>
				<view class="info">
					<view class="name">
						{{info.fullname}} <text>{{info.mobile}}</text>
					</view>
					<view class="add">
						{{info.address}}
					</view>
				</view>
			</view>
			<!-- <u-icon name="arrow-right" color="#ccc"></u-icon> -->
		</view>
		
		<view class="orderList">
			<view class="list">
				<view class="tit">
					<view class="num">商品信息</view>
				</view>
				<view class="goods">
					<image :src="info.goods_data.image" mode=""></image>
					<view class="info">
						<view class="gtit">
							{{info.goods_data.title}}
						</view>
						<view class="peice n-flex-row n-justify-between">
							<view class="p">￥{{info.price}}</view>
							<view class="num">x{{info.number}}</view>
						</view>
					</view>
				</view>
				<view class="row">
					<view>商品总价</view>
					<view class="r">￥{{info.order_price}}</view>
				</view>
				<!-- <view class="row">
					<view>运费</view>
					<view class="r">￥{{info.delivery_fee}}</view>
				</view> -->
			</view>
		</view>
		
		
		
		<view class="wuliu" v-if="info.status == 2 || info.status == 3">
			<view class="tit">
				物流动态
			</view>
			<view class="kuaidi n-flex-row n-justify-between">
				<view class="name">
					<view class="">
						<text style="margin-right: 20rpx;">{{info.express_company}}</text>
						<text>{{info.express_number}}</text>
					</view>
				</view>
				<view class="copy" @click="copy">
					复制
				</view>
			</view>
			<view class="con">
				<u-time-line>
					<!-- 其他 -->
					<u-time-line-item nodeTop="2" v-for="(item,index) in wuliuInfo" :key="index">
						<template v-slot:content>
							<view>
								<view class="u-order-title" v-if="item.status == '签收'">已签收</view>
								<view class="u-order-title" v-if="item.status == '派件'">派件中</view>
								<view class="u-order-title" v-if="item.status == '在途'">运输中</view>
								<view class="u-order-title" v-if="item.status == '揽收'">已揽收</view>
								<view class="u-order-desc">{{item.context}}</view>
								<view class="u-order-time">{{item.time}}</view>
							</view>
						</template>
					</u-time-line-item>
				</u-time-line>
			</view>
		</view>
		
		
		
		<view class="obox">
			<view class="tit">
				订单信息
			</view>
			<view class="row">
				<view>订单时间</view>
				<view class="r1">{{$u.timeFormat(info.create_time, 'yyyy-mm-dd hh:MM:ss')}}</view>
			</view>
			<view class="row">
				<view>来源方式</view>
				<view class="r1">{{info.source_text}}</view>
			</view>
		</view>
		
		<view class="btm" v-if="(info.status == 2)">
			<view class="btmbox">
				<view class="n-flex-row n-align-center">
					<button @click="shouhuo">确认收货</button>
				</view>
			</view>
		</view>
		
		<view style="height: 200rpx;">
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info_id:'',
				info:'',
				wuliuInfo:[],
				lanshou:[],
				zaitu:[],
				paijin:[],
				qianshou:[],
				other:[],
			}
		},
		onLoad(option) {
			this.info_id = option.order_id
			this.getDetails(option.order_id)
		},
		methods: {
			// 单号
			getNum(com,kddh){
				this.$http({
					url: "api/order/get_express_data",
					data:{
						express_company:this.info.express_company,
						express_number:this.info.express_number,
					}
				}).then(res => {
					if (res.data.code == 1) {
						this.wuliuInfo = res.data.data.data
					}else{
						this.$tip.tip(res.data.msg)
					}
				}).catch(err => {});
			},
			shouhuo(){
				this.$http({
					url: "api/order/confirm_deliver",
					data:{
						id:this.info_id
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					if (res.data.code == 1) {
						this.$tip.tip(res.data.msg)
						setTimeout(() => {
							uni.navigateBack()
							uni.$emit('uporder')
						},500)
					}else{
						this.$tip.tip(res.data.msg)
					}
				}).catch(err => {});
			},
			pay(){
				uni.showLoading({
					title:"加载中"
				})
				if(this.info.pay_method == 'wechat'){
					this.weiPay()
				}else if(this.info.pay_method == 'alipay'){
					this.zhiPay()
				}else if(this.info.pay_method == 'lucyk'){
					// #ifdef MP-WEIXIN
					this.weiPay()
					// #endif
					
					// #ifdef APP-PLUS
					this.zhiPay()
					// #endif
					
					
				}
				
			},
			weiPay(){
				this.$http({
					url: "index.php/api/shop/dzfOrder",
					data:{
						ooid:this.ooid
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					// #ifdef H5
					uni.navigateTo({
						url: '/pages/tabBar/pay'
					})
					setTimeout(() => {
						uni.$emit('h5pay', res.data)
					}, 600)
					// #endif
					if (res.data.code == 1) {
						// #ifdef MP-WEIXIN
						var data = res.data.data.data
						uni.requestPayment({
							provider: 'wxpay',
							orderInfo: data,
							appId: data.appId,
							timeStamp: data.timeStamp,
							nonceStr: data.nonceStr,
							package: data.package,
							signType: data.signType,
							paySign: data.paySign,
							success: (res1) => {
								this.$tip.tip("支付成功", "success")
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/mall/paySuccexx'
									})
								}, 700)
							},
							fail: (err) => {
								this.$tip.tip("支付失败")
							}
						});
						// #endif
					}else{
						this.$tip.tip(res.data.msg)
					}
				}).catch(err => {});
			},
			zhiPay(){
				this.$http({
					url: "index.php/api/shop/dzfOrder",
					data:{
						ooid:this.ooid
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					// #ifdef H5
					uni.navigateTo({
						url: '/pages/tabBar/pay'
					})
					setTimeout(() => {
						uni.$emit('h5pay', res.data)
					}, 600)
					// #endif
					if (res.data.code == 1) {
						// #ifdef APP-PLUS
						var data = res.data.data
						uni.requestPayment({
							provider: 'alipay',
							orderInfo: data,
							success: (res1) => {
								this.$tip.tip("支付成功", "success")
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/mall/paySuccexx'
									})
								}, 700)
							},
							fail: (err) => {
								this.$tip.tip("支付失败")
							}
						});
						// #endif
					}else{
						this.$tip.tip(res.data.msg)
					}
				}).catch(err => {});
			},
			getDetails(id){
				this.$http({
					url: "api/order/get_goods_order_info",
					data:{
						order_id:id
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					if (res.data.code == 1) {
						this.info = res.data.data
						if(this.info.status==2 || this.info.status==3){
							this.getNum()
						}
					}else{
						this.$tip.tip(res.data.msg)
					}
				}).catch(err => {});
			},
			copy(){
				uni.setClipboardData({
					data: this.info.kddh,
					success: () => {
						console.log('success');
					}
				});
			},
		}
	}
</script>

<style>
@import url("../../common/css/orderDetails.css");
</style>
